package com.neuedu.controller;


import com.neuedu.pojo.Expend;
import com.neuedu.service.IExpendService;
import com.neuedu.util.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wk
 * @since 2020-09-23
 */
@RestController
@RequestMapping("/expend")
public class ExpendController {
    @Resource
    IExpendService expendService;
    @PostMapping("add")
    CommonResult add(Expend expend){
        return CommonResult.success(expendService.save(expend));
    }
    @PostMapping("list")
    CommonResult list(Expend expend){
        System.out.println("输出");
        System.out.println(expend);
        return expendService.list(expend);
    }
    @GetMapping("getById")
    CommonResult getById(Integer id){
        return CommonResult.success(expendService.getById(id));
    }
    @PostMapping("del")
    CommonResult del(Integer id){
        Expend expend=new Expend();
        expend.setId(id);
        expend.setActive(0);
        boolean i=expendService.updateById(expend);
        if(i){
            return CommonResult.success("删除成功");
        }
        return  CommonResult.failed();
    }

    @PostMapping("back")
    CommonResult back(Integer id){
        Expend expend=new Expend();
        expend.setId(id);
        expend.setActive(1);
        boolean i=expendService.updateById(expend);
        if(i){
            return CommonResult.success("恢复成功");
        }
        return  CommonResult.failed();
    }

    @PostMapping("update")
    CommonResult update(Expend expend){
        System.out.println(expend);
        return CommonResult.success(expendService.updateById(expend));
    }

}
